<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .clock-wrapper {
            width: 200px;
            margin: 50px auto;
            text-align: center;
        }

        .clock-wrapper .clock-time {
            font-size: 40px;
            line-height: 60px;
            height: 60px;
            font-family: "clockIcon";
        }

        .clock-wrapper .clock-date {
            font-size: 16px;
            line-height: 20px;
            height: 20px;
        }

        @font-face {
            font-family: "clockIcon";
            src: url("../font/clockicons.woff2");
        }
    </style>
</head>

<body>
    <div class="clock-wrapper">
        <div class="clock-title">现在时间</div>
        <div class="clock-time"></div>
        <div class="clock-date"></div>
    </div>
</body>
<script>

    var clockTime = document.getElementsByClassName("clock-time")[0];
    var clockDate = document.getElementsByClassName("clock-date")[0];

    // 获取当前时间

    showTime();  //页面加载时执行一次
    setInterval(showTime, 1000);


    function showTime() {
        var date = new Date();

        var year = date.getFullYear();
        var month = date.getMonth() + 1;  //展示到页面中
        var day = date.getDate();

        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();

        clockTime.innerText = `${beauty(hour)}:${beauty(minute)}:${beauty(second)}`;
        clockDate.innerText = `${year}年${beauty(month)}月${beauty(day)}日`;
    }


    function beauty(num) {
        return num < 10 ? "0" + num : num;
    }




</script>

</html>